﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.packCache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.pack.data.*;
    import mortal.game.view.pack.social.*;

    public class TooltipPackGrid extends ToolTipScaleBg
    {
        private var _gridName:GTextFiled;
        private var _dec:GTextFiled;
        private var _const:GTextFiled;
        private var _timeTxt:GTextFiled;
        private var _attrTxt:GTextFiled;
        private var _leftTime:SecTimerView;
        private var _lineBasic1:ScaleBitmap;
        private var _lineBasic2:ScaleBitmap;
        private var _lineBasic3:ScaleBitmap;
        private var _data:PackObject;
        private var _gridInfo:TOpenBagGrid;
        private var _vcAttributeNameText:Vector.<GTextFiled>;
        private var _vcAttributeValueText:Vector.<BitmapNumberText>;

        public function TooltipPackGrid()
        {
            this._vcAttributeNameText = new Vector.<GTextFiled>;
            this._vcAttributeValueText = new Vector.<BitmapNumberText>;
            this.createChildren();
            return;
        }// end function

        public function createChildren() : void
        {
            var _loc_1:GTextFormat = null;
            var _loc_2:int = 10;
            paddingLeft = 10;
            paddingRight = _loc_2;
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.removeEvent);
            setBg(ImagesConst.ToolTipBg);
            _loc_1 = GlobalStyle.textFormatItemGreen.center();
            _loc_1.size = 16;
            this._gridName = new GTextFiled();
            this._gridName.width = 220;
            this._gridName.defaultTextFormat = _loc_1;
            contentContainer2D.addChild(this._gridName);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.size = 13;
            this._dec = new GTextFiled();
            this._dec.width = 220;
            this._dec.height = 100;
            this._dec.defaultTextFormat = _loc_1;
            this._dec.y = 50;
            this._dec.multiline = true;
            this._dec.wordWrap = true;
            contentContainer2D.addChild(this._dec);
            this._const = new GTextFiled();
            this._const.width = 220;
            this._const.height = 70;
            this._const.defaultTextFormat = _loc_1;
            this._const.y = 100;
            this._const.multiline = true;
            this._const.wordWrap = true;
            contentContainer2D.addChild(this._const);
            this._timeTxt = new GTextFiled();
            this._timeTxt.width = 160;
            this._timeTxt.height = 100;
            this._timeTxt.defaultTextFormat = _loc_1;
            this._timeTxt.x = 35;
            this._timeTxt.y = 22;
            contentContainer2D.addChild(this._timeTxt);
            this._attrTxt = new GTextFiled();
            this._attrTxt.width = 220;
            this._attrTxt.height = 30;
            this._attrTxt.defaultTextFormat = GlobalStyle.textFormatHuang2;
            this._attrTxt.y = 22;
            contentContainer2D.addChild(this._attrTxt);
            this._leftTime = new SecTimerView();
            this._leftTime.width = 50;
            this._leftTime.autoSize = TextFieldAutoSize.LEFT;
            this._leftTime.mouseEnabled = false;
            this._leftTime.defaultTextFormat = _loc_1;
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.setParse(Language.getString(30055));
            this._leftTime.x = 90;
            this._leftTime.y = 22;
            this._lineBasic1 = UIFactory.bg(20, 45, 180, 2, contentContainer2D, ImagesConst.SplitLine);
            this._lineBasic2 = UIFactory.bg(20, 95, 180, 2, contentContainer2D, ImagesConst.SplitLine);
            this._lineBasic3 = UIFactory.bg(20, 95, 180, 2, contentContainer2D, ImagesConst.SplitLine);
            return;
        }// end function

        private function removeEvent(event:Event) : void
        {
            this._leftTime.stop();
            this._leftTime.removeEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            return;
        }// end function

        private function addEvent() : void
        {
            this._leftTime.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            return;
        }// end function

        private function updateLeftTime() : void
        {
            var _loc_1:* = Cache.instance.cd.getCDData("lockCD", CDDataType.backPackLock) as CDData;
            if (_loc_1)
            {
                this._leftTime.setLeftTime(_loc_1.leftTime * 0.001);
            }
            if (contentContainer2D)
            {
                contentContainer2D.addChild(this._leftTime);
            }
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 == 0)
            {
                if (contentContainer2D.contains(this._leftTime))
                {
                    contentContainer2D.removeChild(this._leftTime);
                }
            }
            else
            {
                if (!contentContainer2D.contains(this._leftTime))
                {
                    contentContainer2D.addChild(this._leftTime);
                }
                this._const.htmlText = this.openGrideMoney();
            }
            return;
        }// end function

        override public function set data(param1) : void
        {
            this.addEvent();
            this._data = param1;
            var _loc_2:* = Cache.instance.pack.backPackCache;
            var _loc_3:* = this._data.pos - _loc_2.gridVec[0].grid + _loc_2.vipDrid;
            this._gridInfo = _loc_2.gridVec[_loc_3];
            this._gridName.text = Language.getStringByParam(20819, this._data.pos);
            this._const.htmlText = this.openGrideMoney();
            this._dec.x = 0;
            if (this._data.itemData == PackItemData.lockItemData)
            {
                this._timeTxt.text = Language.getString(20820);
                this._dec.htmlText = Language.getString(20821);
                this._leftTime.visible = false;
                this._timeTxt.x = 45;
            }
            else if (this._data.itemData == PackItemData.unLockingItemData)
            {
                this._timeTxt.text = Language.getString(20822);
                this._dec.htmlText = Language.getString(20823);
                this._leftTime.visible = true;
                this._timeTxt.x = 30;
            }
            else if (this._data.itemData == PackItemData.needMoneyItemData)
            {
                this._dec.htmlText = Language.getString(20824);
                this._timeTxt.text = "";
                this._leftTime.visible = false;
            }
            else if (this._data.itemData == PackItemData.unLockItemData)
            {
                this._dec.htmlText = Language.getString(20825);
                this._leftTime.visible = false;
                this._timeTxt.x = 45;
                this._timeTxt.text = Language.getString(20826);
            }
            _scaleBg.width = 180;
            this.updateLeftTime();
            this._lineBasic2.y = this._dec.y + this._dec.textHeight + 8;
            this._const.y = this._lineBasic2.y + 8;
            this._lineBasic3.y = this._const.y + this._const.textHeight + 8;
            this._attrTxt.y = this._lineBasic3.y + 8;
            this.updateAttrList();
            super.data = param1;
            return;
        }// end function

        private function clearAttrList() : void
        {
            var _loc_1:GTextFiled = null;
            var _loc_2:BitmapNumberText = null;
            for each (_loc_1 in this._vcAttributeNameText)
            {
                
                _loc_1.dispose(true);
            }
            for each (_loc_2 in this._vcAttributeValueText)
            {
                
                _loc_2.dispose(true);
            }
            this._vcAttributeNameText.length = 0;
            this._vcAttributeValueText.length = 0;
            return;
        }// end function

        private function updateAttrList() : void
        {
            var _loc_3:GTextFiled = null;
            var _loc_4:BitmapNumberText = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_10:TOpenBagGrid = null;
            var _loc_12:ItemData = null;
            var _loc_13:int = 0;
            var _loc_14:String = null;
            this.clearAttrList();
            var _loc_1:* = GlobalStyle.textFormatAnHuan;
            _loc_1.size = 12;
            var _loc_2:* = MountConfig.instance.attribute;
            var _loc_7:* = Cache.instance.pack.backPackCache;
            var _loc_8:* = _loc_7.gridVec[0].grid + _loc_7.vipDrid;
            var _loc_9:* = _loc_7.capacity - _loc_8;
            if (_loc_9 < 0)
            {
                _loc_10 = null;
            }
            else
            {
                _loc_10 = _loc_7.gridVec[_loc_9];
            }
            var _loc_11:int = 0;
            while (_loc_11 < _loc_2.length)
            {
                
                if (this._gridInfo.hasOwnProperty(_loc_2[_loc_11]))
                {
                    _loc_5 = this._gridInfo[_loc_2[_loc_11]] - (_loc_10 != null ? (_loc_10[_loc_2[_loc_11]]) : (0));
                    if (_loc_5)
                    {
                        _loc_3 = UIFactory.gTextField(GameDefConfig.instance.getAttributeName2(_loc_2[_loc_11]), 15 + _loc_6 % 2 * 104, 12 * (_loc_6 - _loc_6 % 2) + this._attrTxt.y + 20, 55, 20, this, _loc_1);
                        this._vcAttributeNameText.push(_loc_3);
                        _loc_4 = UIFactory.bitmapNumberText(60 + _loc_6 % 2 * 104, 12 * (_loc_6 - _loc_6 % 2) + this._attrTxt.y + 26, "RoleInfoNum.png", 8, 10, -1, this, 14);
                        _loc_4.text = _loc_5.toString();
                        this._vcAttributeValueText.push(_loc_4);
                        _loc_6++;
                    }
                }
                _loc_11++;
            }
            if (this._vcAttributeNameText.length)
            {
                _loc_12 = this._data.itemData as ItemData;
                if (_loc_12 == PackItemData.lockItemData)
                {
                    _loc_13 = this._data.pos - _loc_7.capacity;
                }
                else if (_loc_12 == PackItemData.unLockingItemData)
                {
                    _loc_13 = 1;
                }
                else if (_loc_12 == PackItemData.needMoneyItemData)
                {
                    _loc_13 = this._data.pos - _loc_7.capacity;
                }
                else if (_loc_12 == PackItemData.unLockItemData)
                {
                    _loc_13 = _loc_7.currentGrid - _loc_7.capacity - 1;
                }
                _loc_14 = Language.getStringByParam(20827, _loc_13);
                this._attrTxt.htmlText = _loc_14;
                this._lineBasic3.visible = true;
            }
            else
            {
                this._attrTxt.text = "";
                this._lineBasic3.visible = false;
            }
            return;
        }// end function

        private function openGrideMoney() : String
        {
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_1:* = this._data.itemData as ItemData;
            var _loc_2:* = Cache.instance.pack.backPackCache;
            _loc_4 = ItemFeatureTips.openPackMoney(this._data.pos);
            if (_loc_1 == PackItemData.lockItemData)
            {
                _loc_5 = this._data.pos - _loc_2.capacity;
                _loc_3 = Language.getString(20828) + Language.getStringByParam(30038, _loc_5 - _loc_2.canOpenGridNum, _loc_4);
            }
            else if (_loc_1 == PackItemData.unLockingItemData)
            {
                _loc_3 = Language.getString(20828) + Language.getStringByParam(30037, _loc_4);
                _loc_5 = 1;
            }
            else if (_loc_1 == PackItemData.needMoneyItemData)
            {
                _loc_5 = this._data.pos - _loc_2.capacity;
                _loc_3 = Language.getStringByParam(20829, _loc_5, _loc_4);
            }
            else if (_loc_1 == PackItemData.unLockItemData)
            {
                _loc_5 = _loc_2.currentGrid - _loc_2.capacity - 1;
                var _loc_6:* = Language.getStringByParam(20829, _loc_5, 0);
                _loc_3 = Language.getStringByParam(20829, _loc_5, 0);
                _loc_3 = _loc_6;
            }
            return _loc_3;
        }// end function

    }
}
